package com.example.yuejian21.nongfusanquan.yuejian21.adapter;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.yuejian21.nongfusanquan.yuejian21.R;
import com.example.yuejian21.nongfusanquan.yuejian21.activity.ClubdetailActivtiy;
import com.example.yuejian21.nongfusanquan.yuejian21.javabean.Clubbean;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by Nongfusanquan on 2017-10-12.
 */



    public class ClubAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{
        private Context mContex;
        private List mDataList;
        private LayoutInflater mLayoutInflater;

        public ClubAdapter(Context mContext, List mDataList) {
            this.mContex =  mContext;
            this.mDataList = mDataList;
            mLayoutInflater = LayoutInflater.from(mContext);
        }

        @Override
        public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            View v = mLayoutInflater.from(parent.getContext()).
                    inflate(R.layout.cardview_club, parent, false);
            return new ViewHolder(v);
        }

        @Override
        public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
            final Clubbean entity = (Clubbean) mDataList.get(position);
            if (null == entity)
                return;
            ClubAdapter.ViewHolder viewHolder = (ClubAdapter.ViewHolder) holder;
            viewHolder.t_name.setText(entity.getC_name());
            // viewHolder.t_picture.setImageURI(entity.getT_picture());
            // System.out.println("t_name");
            String t_picture = "http://10.0.2.2/yuejian14/Public/Admin/clubphoto/"+entity.getC_pic();
            if (!t_picture.equals("")) {
                Picasso.with(mContex).load(t_picture).into(viewHolder.t_picture);
            }
            viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Bundle bundle=new Bundle();
                    bundle.putInt("c_id",entity.getC_id());
                    bundle.putString("c_name",entity.getC_name());
                    bundle.putString("c_phone",entity.getC_phone());
                    bundle.putString("c_info",entity.getC_info());
                    bundle.putString("c_pic",entity.getC_pic());
                    Intent intent=new Intent(mContex, ClubdetailActivtiy.class);
                    intent.putExtras(bundle);
                    mContex.startActivity(intent);
                }
            });
        }

        @Override
        public int getItemCount() {
            return mDataList.size();
        }
        public class ViewHolder extends RecyclerView.ViewHolder {
            ImageView t_picture;
            TextView t_name;

            public ViewHolder(View itemView) {
                super(itemView);
                t_name = (TextView) itemView.findViewById(R.id.t_name);
                t_picture = (ImageView) itemView.findViewById(R.id.t_picture);

            }
        }
    }


